/**
 * My simple header template from child directory
 * ChangeCounter.java - ${projectName} - ${organizationName} - ${inceptionYear}
 */
import java.util.Arrays;

import static java.util.Collections.reverseOrder;

/**
 * Created with IntelliJ IDEA.
 * User: Gauss
 * Date: 14.12.13
 * Time: 16:36
 * To change this template use File | Settings | File Templates.
 */
public class ChangeCounter {
    private Integer[] par;
    private int number;

    public ChangeCounter(Integer[] par) {
        this.par = par;
        Arrays.sort(par, reverseOrder());
    }

    public int count(int count) {
        number = 0;
        countRec(count, 0);
        return number;
    }

    private void countRec(int count, int index) {
        if (count==0) {
            number++;
            return;
        }
        for (int i = index; i < par.length; i++) {
            if (par[i] <= count) {
                countRec(count - par[i], i);
            }
        }
    }

}
